package com.logictech.activity.system.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.persistence.mybatis.GenericDaoDefault;
import org.springframework.stereotype.Repository;

import com.logictech.activity.system.dao.SystemUserDao;
import com.logictech.activity.system.entity.SystemUser;
import com.logictech.activity.system.entity.Menu;
import com.logictech.activity.system.vo.LoginUser;

@Repository("systemUserDao")
public class SystemUserDaoImpl extends GenericDaoDefault<SystemUser>implements SystemUserDao {
	public Integer count(PageQuery<SystemUser> pageQuery) {
		return (Integer) super.queryOne("count", new Object[] { pageQuery });
	}

	public List<SystemUser> queryPageList(PageQuery<SystemUser> pageQuery, Integer itemCount) {
		PageQueryWrapper<SystemUser> wrapper = new PageQueryWrapper(pageQuery.getPageNo(), pageQuery.getPageSize(),
				itemCount.intValue(), pageQuery.getQuery());
		return super.query("queryPageList", new Object[] { wrapper });
	}

	public List<String> queryUserRoles(String userId) {
		return super.query("queryUserRoles", new Object[] { userId });
	}

	public List<Menu> queryUserMenuAuth(List<String> roleIds) {
		return super.query("queryUserMenuAuth", new Object[] { roleIds });
	}

	public void insertUserRoleRel(String userId, String roleId) {
		Map<String, String> map = new HashMap();
		map.put("userId", userId);
		map.put("roleId", roleId);
		super.getSqlSession().insert(getStatementId("insertUserRoleRel"), map);
	}

	public void deleteRolesByUserId(String userId) {
		delete("deleteRolesByUserId", new Object[] { userId });
	}

	public LoginUser queryUserByUserId(String userId) {
		return (LoginUser) super.queryOne("queryUserByUserId", new Object[] { userId });
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SystemUser> queryNormalList() {
		return super.query("queryNormalList", new Object());
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<SystemUser> queryAllList() {
		return super.query("queryAllList", new Object());
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SystemUser> queryLoginList() {
		return super.query("queryLoginList", new Object());
	}
}

